package com.JFapp.controller;


import com.JFapp.domain.dto.ChangeRepairStatusDto;
import com.JFapp.domain.entity.Repair;
import com.JFapp.domain.entity.ResponseResult;
import com.JFapp.domain.vo.RepairVo;
import com.JFapp.service.RepairService;
import com.JFapp.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/repair")
@Api(tags = "后台订单管理")
public class RepairController {
    @Autowired
    private RepairService repairService;

    @Autowired
    private UserService userService;

    //查询所有未接订单

    @ApiOperation("查询未接单")
    @GetMapping()
    public ResponseResult<RepairVo> selectRepair(Integer pageNum, Integer pageSize){
        /*Repair repair = (Repair) rabbitTemplate.receiveAndConvert("addRepair");*/
        return  repairService.selectRepair(pageNum,pageSize);
    }


//    @ApiOperation("订单状态通知")
//    @GetMapping("/informNew")
//    public ResponseResult informNew(Repair repair){
//        return repairService.informNew(repair);
//    }


    @ApiOperation("接单与退单")
    @PostMapping("/repairId")
    public ResponseResult receptionRepair(@RequestBody ChangeRepairStatusDto changeRepairStatusDto){
        return repairService.receptionRepair(changeRepairStatusDto);
    }

    @ApiOperation("查询完成的订单")
    @GetMapping("/complete")
    public ResponseResult completeRepair(Integer pageNum, Integer pageSize){
        return repairService.completeRepair(pageNum,pageSize);
    }

    @ApiOperation("查询个人待修单")
    @GetMapping("/repairing")
    public ResponseResult getRepairing(Integer pageNum, Integer pageSize){
        return repairService.getRepairing(pageNum,pageSize);
    }

    @ApiOperation("查询订单详细信息")
    @GetMapping("/{repairId}")
    public ResponseResult getRepairDetail(@PathVariable Long repairId){
        Repair repair = repairService.getById(repairId);
        repair.setPhoneNum(userService.selectPhone(repair.getCreateId()));
        return ResponseResult.okResult(repair);
    }
}
